﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL_NhaSach;
using BLL;

namespace BLL_NhaSach
{
    public class CTHoaDonBLL: IProcessData
    {
        QLNhaSachEntities db;
        public CTHoaDonBLL(String cnStr)
        {
            db = new QLNhaSachEntities(cnStr);
        }
        public object getAllData()
        {
            return (from ct in db.ChiTietHoaDons select new {ct.MaHD,ct.Sach.TenSach,ct.SoLuong,ct.DonGia});
        }

        public object findObjects(string find_content)
        {
            throw new NotImplementedException();
        }

        public object findObjects(int find_content)
        {
            return db.ChiTietHoaDons.SingleOrDefault(p => p.MaHD == find_content);
        }

        public object sort(string Col_Name, bool state)
        {
            throw new NotImplementedException();
        }

        public bool addObject(object addObj)
        {
            ChiTietHoaDon ct = (ChiTietHoaDon)addObj;
            try
            {
                db.ChiTietHoaDons.AddObject(ct);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool deleteObject(int id)
        {
            ChiTietHoaDon ct = db.ChiTietHoaDons.SingleOrDefault(p => p.MaHD == id);
            try
            {
                db.ChiTietHoaDons.DeleteObject(ct);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool updateObject(object updateObj)
        {
            throw new NotImplementedException();
        }
    }
}
